//
//  AppDelegate.m
//  news
//
//  Copyright © 2022 sinosun. All rights reserved.
//

#import "AppDelegate.h"
#import "GTNewsViewController.h"
#import "GTVideoViewController.h"
#import "GTRecommendViewController.h"

@interface AppDelegate () <UITabBarControllerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    // 创建一个Window， 作为APP的主窗口， 一个app只有一个主窗口
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UITabBarController *tabbarControcller = [[UITabBarController alloc] init];
    tabbarControcller.delegate = self;

    
    
    UIViewController *constroller1 = [[UIViewController alloc] init];
    constroller1.view.backgroundColor = [UIColor whiteColor];
    [constroller1.view addSubview:({
        UILabel* label = [[UILabel alloc] init];
        label.text = @"这是UINavigationController里面的UIViewController";
        [label sizeToFit];
        label.center = CGPointMake(constroller1.view.frame.size.width/2, constroller1.view.frame.size.height/2);
        label;
    })];
    
    GTNewsViewController *newsViewController = [[GTNewsViewController alloc] init];
    UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:newsViewController];
    navigationController.tabBarItem.title = @"新闻";

    GTVideoViewController *videoController = [[GTVideoViewController alloc] init];
    

    GTRecommendViewController *recommendViewController = [[GTRecommendViewController alloc] init];
    

    UIViewController *constroller4 = [[UIViewController alloc] init];
    constroller4.view.backgroundColor = [UIColor greenColor];
    constroller4.tabBarItem.title = @"我的";

    [tabbarControcller setViewControllers:@[navigationController, videoController, recommendViewController, constroller4]];

    // 设置主的Controcller
    self.window.rootViewController = tabbarControcller;
    [self.window makeKeyAndVisible];
    
    
    return YES;
}

#pragma mark --UITabBarControllerDelegate
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"didSelectViewController");
}
@end
